// pages/tabBar/cate/cate.js
import {
  Config
} from "../../../utils/config.js";
import api from "../../../utils/api.js"
import * as com from "../../../utils/common.js"
const Base = new com.Base();
var app = getApp();

Page({
  data: {
    cartGoods: [{
        id: 1,
        checked: 1,
        list_pic_url: '/images/03.jpg',
        goods_name: '2条装 男式梭织绅士内裤',
        number: 10,
        isEditCart: 1,
        goods_specifition_name_value: 'XL 藏青方格+黑红千鸟格',
        retail_price: 12.00
      },
      {
        id: 1,
        checked: 1,
        list_pic_url: '/images/03.jpg',
        goods_name: 'asd',
        number: 10,
        isEditCart: 1,
        goods_specifition_name_value: '1231231231312',
        retail_price: 12.00
      },
      {
        id: 1,
        checked: 1,
        list_pic_url: '/images/03.jpg',
        goods_name: 'asd',
        number: 10,
        isEditCart: 1,
        goods_specifition_name_value: '1231231231312',
        retail_price: 12.00
      },
    ],

    // 是否登录
    isLogin: false,

    cartTotal: {
      "goodsCount": 0,
      "goodsAmount": 0.00,
      "checkedGoodsCount": 0,
      "checkedGoodsAmount": 0.00
    },

    isEditCart: false,

    checkedAllStatus: true,

    editCartList: [],

    // 开始滑动坐标
    clientX: null,

    isShowDelBtn: null
  },

  // 滑动开始
  touchstart: function(e) {
    // 开始滑动坐标
    this.setData({
      clientX: e.changedTouches[0].clientX
    })
  },

  // 滑动移动事件
  touchmove: function(e) {

    // 获取当前滑动id
    var currentID = e.currentTarget.dataset.index

    // 获取滑动 距离
    var distanceX = e.changedTouches[0].clientX - this.data.clientX;

    if (distanceX > 30) { //右滑

      this.setData({
        isShowDelBtn: -1,
      })
    } else if (distanceX < -30) {

      this.setData({
        // 滑动时 显示 删除按钮
        isShowDelBtn: currentID,
      })
    }


  },

  onLoad() {
    this.see_is_login();
    console.log('onLoad')
  },

  onShow() {
    console.log('onShow')    
  },

  // 是否登录
  see_is_login() {
    wx.getSetting({
      success: (res) => {
        if (res.authSetting['scope.userInfo']) {
          console.log('已登录')
          this.setData({
            isLogin: true
          })
        } else {
          this.setData({
            isLogin: false
          })
        }
      }
    })
  }


})